package com.example.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.administrator.myapplication.R;
;

import android.util.Log;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by Administrator on 2022/6/4.
 */

public class DButils {
    private static String user = "root";
    private static String password = "root";
    private static String url = "jdbc:mysql://10.21.151.218:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true";
    private Connection conn=null;

    public  void linkDatabase()
    {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Log.i("msg","连接");
                    Class.forName("com.mysql.jdbc.Driver");
                    conn=(DriverManager.getConnection(url,user,password));
                    if(conn!=null)
                    {
                        Log.i("msg","连接成功");
                    }
                    else
                    {
                        Log.i("msg","连接失败");

                    }
                }catch (ClassNotFoundException e)
                {
                    Log.i("msg","出错了");
                    e.printStackTrace();
                }catch (SQLException e)
                {
                    Log.i("msg",e.getMessage());
                }catch (Exception e)
                {
                    Log.i("error","错了");
                    e.printStackTrace();
                }
            }
        }).start();
    }

}
